package com.sskj.mine.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.App;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.LanguageUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.bean.WalletXieyiBean;
import com.sskj.mine.bean.WebUrl;
import com.sskj.mine.bean.XieyiBean;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.ui.activity.MineNewsDetailActivity;

import java.util.Locale;


public class MineNewsDetailActivityPresenter extends BasePresenter<MineNewsDetailActivity> {
    // 获取协议
    public void getContent(String id) {
        OkGo.<HttpData<WebUrl>>post(HttpConfig.BASE_URL + HttpConfig.NEWSLISTITEM)
                .params("id", id)
                .execute(new JsonCallBack<HttpData<WebUrl>>(this, true) {
                    @Override
                    public void onSuccess(Response<HttpData<WebUrl>> response) {
                        HttpData<WebUrl> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateContent(httpData.getData());
                        }
                    }
                });
    }

    public void getXieyi() {
        httpService.getXieyi()
                .execute(new JsonCallBack<HttpData<XieyiBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<XieyiBean>> response) {
                        HttpData<XieyiBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateContent(httpData.getData().getReg_agree());
                        }
                    }
                });
    }

    public void getWalletXieyi() {
        httpService.getWalletXieyi()
                .execute(new JsonCallBack<HttpData<WalletXieyiBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<WalletXieyiBean>> response) {
                        HttpData<WalletXieyiBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            if ((LanguageUtil.getAppLocale(App.INSTANCE) == Locale.ENGLISH)) {
                                mView.updateContent(httpData.getData().getBx_agree_en());
                            } else {
                                mView.updateContent(httpData.getData().getBx_agree());

                            }
                        }
                    }
                });
    }
}
